// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.16/esri/copyright.txt for details.
//>>built
define("require dojo/_base/lang dojo/_base/array dojo/_base/connect dojo/_base/Deferred dojo/_base/json dojo/_base/url dojo/on dojo/DeferredList dojo/dom-construct dojo/sniff esri/kernel esri/config esri/lang esri/request esri/SpatialReference esri/map esri/urlUtils esri/geometry/ScreenPoint esri/geometry/Extent esri/geometry/webMercatorUtils esri/symbols/jsonUtils esri/renderers/jsonUtils esri/dijit/PopupTemplate esri/dijit/Popup esri/tasks/query esri/tasks/GeometryService esri/layers/ArcGISTiledMapServiceLayer esri/layers/FeatureLayer dojo/i18n!esri/nls/jsapi".split(" "),
    function (H, n, k, t, r, I, vb, Da, C, wb, Ea, G, J, l, z, B, xb, Fa, Ga, D, yb, E, K, Ha, zb, Ab, Bb, Cb, u, ha) {
        function F(a) {
            return z({
                url: s.arcgisUrl + "/" + a.itemId + "/data",
                content: {f: "json"},
                callbackParamName: "callback"
            }, {disableIdentityLookup: !0, _preLookup: !0})
        }

        function ia(a, e) {
            var d = {f: "json"};
            e && (d.token = e);
            return z({url: a, content: d, callbackParamName: "callback"}, {disableIdentityLookup: !0})
        }

        function ja(a) {
            a.itemProperties.layerDefinition && (a.layerDefinition ? (a.layerDefinition.drawingInfo || (a.layerDefinition.drawingInfo = a.itemProperties.layerDefinition.drawingInfo),
            l.isDefined(a.layerDefinition.definitionExpression) || (a.layerDefinition.definitionExpression = a.itemProperties.layerDefinition.definitionExpression), l.isDefined(a.layerDefinition.minScale) || (a.layerDefinition.minScale = a.itemProperties.layerDefinition.minScale), l.isDefined(a.layerDefinition.maxScale) || (a.layerDefinition.maxScale = a.itemProperties.layerDefinition.maxScale)) : a.layerDefinition = a.itemProperties.layerDefinition);
            a.itemProperties.popupInfo && (!a.popupInfo && !a.disablePopup) && (a.popupInfo = a.itemProperties.popupInfo);
            l.isDefined(a.itemProperties.showLabels) && !l.isDefined(a.showLabels) && (a.showLabels = a.itemProperties.showLabels);
            l.isDefined(a.itemProperties.showLegend) && !l.isDefined(a.showLegend) && (a.showLegend = a.itemProperties.showLegend);
            l.isDefined(a.itemProperties.refreshInterval) && !l.isDefined(a.refreshInterval) && (a.refreshInterval = a.itemProperties.refreshInterval)
        }

        function Ia(a) {
            ja(a);
            a.itemProperties.layerDefinition && a.layerDefinition && (!l.isDefined(a.layerDefinition.maximumTrackPoints) && l.isDefined(a.itemProperties.layerDefinition.maximumTrackPoints) &&
            (a.layerDefinition.maximumTrackPoints = a.itemProperties.layerDefinition.maximumTrackPoints), !a.layerDefinition.definitionGeometry && a.itemProperties.layerDefinition.definitionGeometry && (a.layerDefinition.definitionGeometry = a.itemProperties.layerDefinition.definitionGeometry));
            a.itemProperties.purgeOptions && !a.purgeOptions && (a.purgeOptions = a.itemProperties.purgeOptions)
        }

        function L(a, e) {
            var d = new r, c = a.itemData, b = [], f = [];
            k.forEach(c.operationalLayers, function (a) {
                if (a.itemId && !a.type) {
                    var d = a.url.toLowerCase();
                    -1 < d.indexOf("/featureserver") || -1 < d.indexOf("/mapserver/") ? (f.push(a), b.push(F(a))) : -1 < d.indexOf("/mapserver") && -1 === d.indexOf("/mapserver/") && (!a.layers || !l.isDefined(a.minScale) && !l.isDefined(a.maxScale)) ? (f.push(a), b.push(F(a))) : -1 < d.indexOf("/imageserver") && !l.isDefined(a.minScale) && !l.isDefined(a.maxScale) ? (f.push(a), b.push(F(a))) : -1 < d.indexOf("/streamserver") && (f.push(a), b.push(F(a)))
                }
            });
            c.baseMap && c.baseMap.baseMapLayers && k.forEach(c.baseMap.baseMapLayers, function (a) {
                a.itemId && "VectorTileLayer" !==
                a.layerType && (f.push(a), b.push(F(a)))
            });
            if (0 < b.length) {
                var g = {};
                (new C(b)).addCallback(function (c) {
                    k.forEach(f, function (a, d) {
                        var b = c[d][1];
                        if (b && !(b instanceof Error) && (g[a.itemId] = b, !a.type)) {
                            var f = a.url.toLowerCase();
                            if ((-1 < f.indexOf("/featureserver") || -1 < f.indexOf("/mapserver/")) && b.layers)k.forEach(b.layers, function (b) {
                                if (f.match("/featureserver/" + b.id + "$") == "/featureserver/" + b.id || f.match("/mapserver/" + b.id + "$") == "/mapserver/" + b.id)a.itemProperties = b, ja(a)
                            }); else if (-1 < f.indexOf("/streamserver"))a.itemProperties =
                                b, Ia(a); else if (-1 < f.indexOf("/mapserver"))b.layers && !a.layers && (a.layers = b.layers), l.isDefined(b.minScale) && !l.isDefined(a.minScale) && (a.minScale = b.minScale), l.isDefined(b.maxScale) && !l.isDefined(a.maxScale) && (a.maxScale = b.maxScale), l.isDefined(b.refreshInterval) && !l.isDefined(a.refreshInterval) && (a.refreshInterval = b.refreshInterval), b.visibleLayers && !a.visibleLayers && (a.visibleLayers = b.visibleLayers); else if (-1 < f.indexOf("/imageserver") && (l.isDefined(b.minScale) && !l.isDefined(a.minScale) && (a.minScale =
                                    b.minScale), l.isDefined(b.maxScale) && !l.isDefined(a.maxScale) && (a.maxScale = b.maxScale), l.isDefined(b.refreshInterval) && !l.isDefined(a.refreshInterval) && (a.refreshInterval = b.refreshInterval), b.popupInfo && (!a.popupInfo && !a.disablePopup) && (a.popupInfo = b.popupInfo), b.renderingRule && !a.renderingRule && (a.renderingRule = b.renderingRule, b.renderingRule.functionName && (a.renderingRule.rasterFunction = b.renderingRule.functionName)), b.bandIds && !a.bandIds && (a.bandIds = b.bandIds), b.mosaicRule && !a.mosaicRule && (a.mosaicRule =
                                    b.mosaicRule), b.format && !a.format && (a.format = b.format), l.isDefined(b.compressionQuality) && !l.isDefined(a.compressionQuality) && (a.compressionQuality = b.compressionQuality), b.layerDefinition && b.layerDefinition.definitionExpression && (!l.isDefined(a.layerDefinition) || !l.isDefined(a.layerDefinition.definitionExpression))))a.layerDefinition = a.layerDefinition || {}, a.layerDefinition.definitionExpression = b.layerDefinition.definitionExpression
                        }
                    });
                    a.relatedItemsData = g;
                    d.callback(a)
                })
            } else d.callback(a);
            return d
        }

        function Db(a, e) {
            var d = new r, c = a.itemData, b = c.baseMap.baseMapLayers[0];
            if ("BingMapsAerial" === b.type || "BingMapsRoad" === b.type || "BingMapsHybrid" === b.type)if (b.portalUrl && G.id)delete e.bingMapsKey, G.id.checkSignInStatus(Fa.urlToObject(s.arcgisUrl).path).then(n.hitch(null, function (a, d, c, f, e) {
                ia(b.portalUrl, e.token).then(n.hitch(null, ka, a, d, c, f), n.hitch(null, M, a, d, c, f))
            }, a, e, c, d), n.hitch(null, function (a, d, c, f, e) {
                ia(b.portalUrl).then(n.hitch(null, ka, a, d, c, f), n.hitch(null, M, a, d, c, f))
            }, a, e, c, d)); else if (e.bingMapsKey) {
                var f =
                    new w({bingMapsKey: e.bingMapsKey, mapStyle: w.MAP_STYLE_AERIAL});
                t.connect(f, "onLoad", n.hitch(this, function () {
                    d.callback([a, e])
                }));
                t.connect(f, "onError", function (g) {
                    delete e.bingMapsKey;
                    a.itemData = N(c);
                    b = a.itemData.baseMap.baseMapLayers[0];
                    b.errors = [];
                    b.errors.push({message: "The owner of the application has not provided a valid Bing Key for the Bing Map it includes. Switching to Esri layers."});
                    d.callback([a, e])
                })
            } else a.itemData = N(c), b = a.itemData.baseMap.baseMapLayers[0], b.errors = [], b.errors.push({message: "The owner of the application has not provided a Bing Key for the Bing Map it includes. Switching to Esri layers."}),
                d.callback([a, e]); else d.callback([a, e]);
            return d
        }

        function Eb(a) {
            var e = new r, d, c;
            a = a.itemData;
            var b = a.baseMap && a.baseMap.baseMapLayers;
            if (Ea("ie") || la && !la.supported())for (a = 0; a < b.length; a++) {
                var f = b[a];
                if (!f.isReference) {
                    "VectorTileLayer" === f.layerType && (d = f.itemId, c = a);
                    break
                }
            }
            d ? ma(d, !1).addBoth(function (a) {
                var d = /^https?:\/\/basemaps(dev)?\.arcgis\.com\/arcgis\/rest\/services\/World_Basemap\/VectorTileServer/i;
                a && (a.item && d.test(a.item.url)) && (b[c] = {
                    id: "FB_" + f.id,
                    layerType: "ArcGISTiledMapServiceLayer",
                    opacity: "opacity" in f ? f.opacity : 1,
                    visibility: "visibility" in f ? f.visibility : !0,
                    url: "http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer"
                });
                e.resolve()
            }) : e.resolve();
            return e
        }

        function ka(a, e, d, c, b) {
            b.bingKey ? (e.bingMapsKey = b.bingKey, b = new w({
                bingMapsKey: e.bingMapsKey,
                mapStyle: w.MAP_STYLE_AERIAL
            }), t.connect(b, "onLoad", n.hitch(this, function () {
                c.callback([a, e])
            })), t.connect(b, "onError", function (b) {
                delete e.bingMapsKey;
                a.itemData = N(d);
                b = a.itemData.baseMap.baseMapLayers[0];
                b.errors =
                    [];
                b.errors.push({message: "The owner of the map has not provided a valid Bing Key for the Bing Map it includes. Switching to Esri layers."});
                c.callback([a, e])
            })) : M(a, e, d, c)
        }

        function M(a, e, d, c) {
            delete e.bingMapsKey;
            a.itemData = N(d);
            d = a.itemData.baseMap.baseMapLayers[0];
            d.errors = [];
            d.errors.push({message: "The owner of the map has not provided a Bing Key for the Bing Map it includes. Switching to Esri layers."});
            c.callback([a, e])
        }

        function N(a) {
            a.baseMap = "BingMapsAerial" === a.baseMap.baseMapLayers[0].type ?
            {
                title: "Imagery",
                baseMapLayers: [{
                    id: "World_Imagery_2017",
                    visibility: !0,
                    opacity: 1,
                    url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
                }]
            } : "BingMapsRoad" === a.baseMap.baseMapLayers[0].type ? {
                title: "Streets",
                baseMapLayers: [{
                    id: "World_Street_Map_8421",
                    opacity: 1,
                    visibility: !0,
                    url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
                }]
            } : {
                title: "Imagery with Labels",
                baseMapLayers: [{
                    id: "World_Imagery_6611",
                    opacity: 1,
                    visibility: !0,
                    url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
                },
                    {
                        id: "World_Boundaries_and_Places_1145",
                        isReference: !0,
                        opacity: 1,
                        visibility: !0,
                        url: "http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer"
                    }]
            };
            return a
        }

        function na(a, e, d, c) {
            var b = a.dynamicLayerInfos || a.layerInfos, f = e.layers;
            if (f && b)if (c.usePopupManager) {
                var g;
                k.forEach(b, function (a) {
                    var b = a.id;
                    if (!a.subLayerIds)for (a = 0; a < f.length; a++) {
                        var c = f[a];
                        if (c.id === b && c.popupInfo) {
                            g || (g = {});
                            g[b] = {infoTemplate: new d(c.popupInfo), layerUrl: c.layerUrl};
                            break
                        }
                    }
                });
                g &&
                a.setInfoTemplates(g)
            } else {
                var h = [], m = [], v = [], p = [], q = [], Ja = [];
                k.forEach(b, function (b) {
                    var d = b.id;
                    if (!b.subLayerIds && -1 !== k.indexOf(a.visibleLayers, d))for (b = 0; b < f.length; b++) {
                        var c = f[b];
                        if (c.id === d) {
                            m.push(d);
                            h.push(c.popupInfo);
                            v.push(c.layerUrl || "");
                            c.layerDefinition && c.layerDefinition.definitionExpression ? p.push(c.layerDefinition.definitionExpression) : p.push("");
                            q.push(l.isDefined(c.minScale) ? c.minScale : null);
                            Ja.push(l.isDefined(c.maxScale) ? c.maxScale : null);
                            break
                        }
                    }
                });
                h.length && (a.__popups = h, a.__popupIds =
                    m, a.__popupUrls = v, a.__popupWhereClauses = p, a.__popupMinScales = q, a.__popupMaxScales = Ja, a.__resourceInfo = e.resourceInfo)
            }
        }

        function oa(a) {
            if (!a)return !1;
            var e = (new vb(s.arcgisUrl)).authority;
            return -1 !== a.indexOf(".arcgis.com/") || -1 !== a.indexOf(e)
        }

        function Ka(a) {
            return !a ? !1 : -1 !== a.indexOf("/services.arcgisonline.com/") || -1 !== a.indexOf("/server.arcgisonline.com/")
        }

        function A(a) {
            if ("https:" === location.protocol && (oa(a) || Ka(a)))a = a.replace("http:", "https:");
            return a
        }

        function pa(a, e, d) {
            var c = [], b;
            a.displayLevels ||
            (c = k.map(a.resourceInfo.tileInfo.lods, function (a) {
                return a.level
            }));
            a.exclusionAreas && (b = n.clone(a.exclusionAreas), b = k.map(b, function (a) {
                a.geometry = new D(a.geometry);
                return a
            }));
            c = new Cb(A(a.url), {
                resourceInfo: a.resourceInfo,
                opacity: a.opacity,
                visible: a.visibility,
                displayLevels: a.displayLevels || c,
                id: a.id,
                minScale: a.minScale,
                maxScale: a.maxScale,
                refreshInterval: a.refreshInterval,
                exclusionAreas: b
            });
            d.ignorePopups || na(c, a, e, d);
            return c
        }

        function qa(a, e) {
            if (!a || !e || 0 === e.length)return [];
            var d = "," + e + ",",
                c = [], b, f = ",";
            for (b = 0; b < a.length; b++)if (null !== a[b].subLayerIds) {
                if (-1 === d.indexOf("," + a[b].id + ",") || -1 < f.indexOf("," + a[b].id + ","))f += a[b].subLayerIds.toString() + ","
            } else-1 < d.indexOf("," + a[b].id + ",") && -1 === f.indexOf("," + a[b].id + ",") && c.push(a[b].id);
            return c
        }

        function La(a, e, d) {
            var c = new Ma;
            c.format = "png24";
            a.resourceInfo && (a.resourceInfo.supportedImageFormatTypes && -1 < a.resourceInfo.supportedImageFormatTypes.indexOf("PNG32")) && (c.format = "png32");
            var c = new Na(A(a.url), {
                resourceInfo: a.resourceInfo,
                opacity: a.opacity,
                visible: a.visibility,
                id: a.id,
                imageParameters: c,
                minScale: a.minScale,
                maxScale: a.maxScale,
                refreshInterval: a.refreshInterval
            }), b = a.visibleLayers;
            if (!a.visibleLayers) {
                var f = "";
                k.forEach(c.layerInfos, function (a) {
                    a.defaultVisibility && (f += (0 < f.length ? "," : "") + a.id)
                });
                b = f
            }
            if (a.layers && 0 < a.layers.length) {
                var g = [], h = [], m, v = [], p, q;
                k.forEach(a.layers, function (b) {
                    b.layerDefinition && b.layerDefinition.definitionExpression && (g[b.id] = b.layerDefinition.definitionExpression);
                    if (b.layerDefinition && b.layerDefinition.source) {
                        m =
                            null;
                        q = b.layerDefinition.source;
                        if ("mapLayer" === q.type) {
                            var d = k.filter(a.resourceInfo.layers, function (a) {
                                return a.id === q.mapLayerId
                            });
                            d.length && (m = n.mixin(d[0], b))
                        } else m = n.mixin({}, b);
                        m && (m.source = q, delete m.popupInfo, m = new Oa(m), a.visibleLayers && (d = "string" == typeof a.visibleLayers ? a.visibleLayers.split(",") : a.visibleLayers, -1 < k.indexOf(d, b.id) ? m.defaultVisibility = !0 : m.defaultVisibility = !1), h.push(m))
                    }
                    b.layerDefinition && (b.layerDefinition.source && b.layerDefinition.drawingInfo) && (p = new Pa(b.layerDefinition.drawingInfo),
                        v[b.id] = p)
                }, this);
                0 < g.length && c.setLayerDefinitions(g);
                0 < h.length ? (c.setDynamicLayerInfos(h, !0), 0 < v.length && c.setLayerDrawingOptions(v, !0)) : (b = qa(c.layerInfos, b), c.setVisibleLayers(b))
            } else b = qa(c.layerInfos, b), c.setVisibleLayers(b);
            d.ignorePopups || na(c, a, e, d);
            return c
        }

        function Fb(a, e, d) {
            var c = new Qa;
            c.bandIds = a.bandIds;
            null != a.format && (c.format = a.format, null != a.compressionQuality && (c.compressionQuality = a.compressionQuality));
            if (a.renderingRule && a.renderingRule.rasterFunction) {
                var b = new Ra(a.renderingRule);
                c.renderingRule = b
            }
            a.mosaicRule && (b = new Sa(a.mosaicRule), c.mosaicRule = b);
            l.isDefined(a.noData) && (c.noData = a.noData);
            l.isDefined(a.noDataInterpretation) && (c.noDataInterpretation = a.noDataInterpretation);
            l.isDefined(a.interpolation) && (c.interpolation = a.interpolation);
            b = a.layerType ? "ArcGISImageServiceVectorLayer" === a.layerType : !1;
            l.isDefined(a.layerType) || (b = a.resourceInfo.hasMultidimensions && ("esriImageServiceDataTypeVector-UV" === a.resourceInfo.serviceDataType || "esriImageServiceDataTypeVector-MagDir" ===
                a.resourceInfo.serviceDataType));
            c = {
                resourceInfo: a.resourceInfo,
                opacity: a.opacity,
                visible: a.visibility,
                id: a.id,
                imageServiceParameters: c,
                minScale: a.minScale,
                maxScale: a.maxScale,
                refreshInterval: a.refreshInterval
            };
            c = b ? new Ta(A(a.url), c) : new Ua(A(a.url), c);
            a.layerDefinition && (a.layerDefinition.drawingInfo && a.layerDefinition.drawingInfo.renderer && (b = K.fromJson(a.layerDefinition.drawingInfo.renderer), c.setRenderer(b)), a.layerDefinition.definitionExpression && c.setDefinitionExpression(a.layerDefinition.definitionExpression,
                !0));
            !d.ignorePopups && a.popupInfo && c.setInfoTemplate(new e(a.popupInfo));
            return c
        }

        function ra(a, e, d) {
            var c = [102113, 102100, 3857], b = d || new B(e[0].layerObject.fullExtent.spatialReference), f = new B(a.resourceInfo.fullExtent.spatialReference);
            return b.wkt == f.wkt && (b.wkid == f.wkid || l.isDefined(b.latestWkid) && b.latestWkid == f.wkid || l.isDefined(f.latestWkid) && b.wkid == f.latestWkid || l.isDefined(b.latestWkid) && b.latestWkid == f.latestWkid) || b.wkid && f.wkid && k.some(c, function (a) {
                return a === f.wkid
            }) && k.some(c, function (a) {
                return a ===
                    b.wkid
            }) ? !0 : !1
        }

        function sa(a, e, d) {
            if (!e[0].layerObject.tileInfo)return !1;
            a = a.resourceInfo.tileInfo;
            e = e[0].layerObject.tileInfo;
            d = d.width > d.height ? d.width : d.height;
            for (var c = !1, b = !1, f = 0; f < a.lods.length; f++) {
                for (var g = a.lods[f].scale / a.dpi, h = 0; h < e.lods.length; h++) {
                    var m = e.lods[h].scale / e.dpi;
                    if (Math.abs(m - g) / m < 1 / d)if (c) {
                        b = !0;
                        break
                    } else c = !0
                }
                if (b)break
            }
            return b || c && (1 === a.lods.length || 1 === e.lods.length) ? !0 : !1
        }

        function Va(a, e, d, c, b, f) {
            var g, h = d._clazz;
            if ("OpenStreetMap" === a.type)g = new Wa({
                id: a.id, opacity: a.opacity,
                visible: null !== a.visibility && void 0 !== a.visibility ? a.visibility : !0
            }); else if ("WMS" === a.type) {
                var m = [], v = [];
                k.forEach(a.layers, function (a) {
                    v.push(new Xa({name: a.name, title: a.title, legendURL: a.legendURL}));
                    m.push(a.name)
                }, this);
                a.visibleLayers && (m = a.visibleLayers);
                c = {
                    extent: new D(a.extent[0][0], a.extent[0][1], a.extent[1][0], a.extent[1][1], new B({wkid: 4326})),
                    layerInfos: v,
                    version: a.version,
                    maxWidth: a.maxWidth,
                    maxHeight: a.maxHeight,
                    getMapURL: a.mapUrl,
                    spatialReferences: a.spatialReferences,
                    title: a.title,
                    copyright: a.copyright,
                    minScale: a.minScale || 0,
                    maxScale: a.maxScale || 0,
                    format: a.format
                };
                g = new Ya(a.url, {
                    id: a.id,
                    visibleLayers: m,
                    format: "png",
                    transparent: a.firstLayer ? !1 : !0,
                    opacity: a.opacity,
                    visible: null !== a.visibility ? a.visibility : !0,
                    resourceInfo: c,
                    refreshInterval: a.refreshInterval
                });
                g.spatialReference.wkid = c.spatialReferences[0]
            } else if ("KML" === a.type) {
                d = a.url;
                if (G.id && (h = G.id.findCredential(Fa.urlToObject(s.arcgisUrl).path))) {
                    var p = s.arcgisUrl.substring(s.arcgisUrl.indexOf("//") + 2, s.arcgisUrl.indexOf("/",
                        s.arcgisUrl.indexOf("//") + 3)), q = p.split("."), q = q[q.length - 2] + "." + q[q.length - 1];
                    e = d.indexOf(q);
                    -1 < e && (d = "https://" + p + d.substring(e + q.length), d += "?token\x3d" + h.token)
                }
                g = new Za(d, {
                    id: a.id,
                    visible: null !== a.visibility ? a.visibility : !0,
                    outSR: c,
                    refreshInterval: a.refreshInterval
                });
                t.connect(g, "onLoad", function () {
                    (a.opacity || 0 === a.opacity) && g.setOpacity(a.opacity);
                    l.isDefined(a.minScale) && l.isDefined(a.maxScale) && g.setScaleRange(a.minScale, a.maxScale);
                    a.visibleFolders && k.forEach(g.folders, function (b) {
                        -1 < k.indexOf(a.visibleFolders,
                            b.id) ? g.setFolderVisibility(b, !0) : g.setFolderVisibility(b, !1)
                    }, this)
                })
            } else"WebTiledLayer" === a.type ? (g = new $a(a.templateUrl, {
                id: a.id,
                visible: null !== a.visibility ? a.visibility : !0,
                opacity: a.opacity,
                copyright: a.copyright,
                fullExtent: a.fullExtent && new D(a.fullExtent),
                initialExtent: a.fullExtent && new D(a.fullExtent),
                subDomains: a.subDomains,
                tileInfo: a.tileInfo ? new ab(a.tileInfo) : null,
                refreshInterval: a.refreshInterval
            }), t.connect(g, "onLoad", function () {
                (l.isDefined(a.minScale) || l.isDefined(a.maxScale)) && g.setScaleRange(a.minScale,
                    a.maxScale)
            })) : "GeoRSS" === a.type ? (g = new bb(a.url, {
                id: a.id,
                opacity: a.opacity,
                outSpatialReference: c,
                refreshInterval: a.refreshInterval
            }), t.connect(g, "onLoad", function () {
                !1 === a.visibility && g.hide();
                l.isDefined(a.minScale) && l.isDefined(a.maxScale) && g.setScaleRange(a.minScale, a.maxScale);
                var b = g.getFeatureLayers();
                k.forEach(b, function (d) {
                    a.pointSymbol && "esriGeometryPoint" === d.geometryType ? (d.renderer.symbol = E.fromJson(a.pointSymbol), 1 === b.length && (g.pointSymbol = E.fromJson(a.pointSymbol))) : a.lineSymbol &&
                    "esriGeometryPolyline" === d.geometryType ? (d.renderer.symbol = E.fromJson(a.lineSymbol), 1 === b.length && (g.polylineSymbol = E.fromJson(a.lineSymbol))) : a.polygonSymbol && "esriGeometryPolygon" === d.geometryType && (d.renderer.symbol = E.fromJson(a.polygonSymbol), 1 === b.length && (g.polygonSymbol = E.fromJson(a.polygonSymbol)))
                })
            })) : "CSV" == a.type && a.url ? (c = {
                layerDefinition: a.layerDefinition,
                columnDelimiter: a.columnDelimiter,
                id: a.id ? a.id : null,
                visible: null !== a.visibility ? a.visibility : !0,
                opacity: a.opacity,
                refreshInterval: a.refreshInterval
            },
            a.locationInfo && (c.latitudeFieldName = a.locationInfo.latitudeFieldName, c.longitudeFieldName = a.locationInfo.longitudeFieldName), d.ignorePopups || (c.infoTemplate = new Ha(a.popupInfo ? a.popupInfo : cb.generateDefaultPopupInfo(a))), g = new db(a.url, c)) : "VectorTileLayer" === a.layerType && a.styleUrl ? g = new eb(a.styleUrl, {
                id: a.id,
                minScale: a.minScale,
                maxScale: a.maxScale,
                opacity: a.opacity,
                visible: a.visibility
            }) : a.layerDefinition && !a.url ? (c = I.fromJson(I.toJson(a)), delete c.id, delete c.opacity, delete c.visibility, g = new u(c,
                {
                    id: a.id,
                    opacity: a.opacity,
                    visible: a.visibility,
                    outFields: ["*"],
                    autoGeneralize: !0
                }), !d.ignorePopups && c.popupInfo && g.setInfoTemplate(new h(c.popupInfo)), fb(g)) : "BingMapsAerial" === a.type || "BingMapsRoad" === a.type || "BingMapsHybrid" === a.type ? d.bingMapsKey ? (c = w.MAP_STYLE_AERIAL_WITH_LABELS, "BingMapsAerial" === a.type ? c = w.MAP_STYLE_AERIAL : "BingMapsRoad" === a.type && (c = w.MAP_STYLE_ROAD), g = new w({
                bingMapsKey: d.bingMapsKey,
                mapStyle: c,
                opacity: a.opacity,
                id: a.id
            }), t.connect(g, "onError", n.hitch(this, function (a) {
                a.errors =
                    a.errors || [];
                a.errors.push({message: "This application does not have a valid Bing Key for the Bing layer that is included in this map. [type:" + a.type + "]"})
            }, a))) : (a.errors = a.errors || [], a.errors.push({message: "This application does not provide a Bing Key for the Bing layer that is included in this map. [type:" + a.type + "]"})) : a.resourceInfo && a.resourceInfo.mapName ? g = !0 === a.resourceInfo.singleFusedMapCache && (a.baseMapLayer || ra(a, e, c) && sa(a, b, f)) ? pa(a, h, d) : La(a, h, d) : a.resourceInfo && a.resourceInfo.pixelSizeX ?
                g = !0 === a.resourceInfo.singleFusedMapCache && (a.baseMapLayer || ra(a, e, c) && sa(a, b, f)) ? pa(a, h, d) : Fb(a, h, d) : a.resourceInfo && "Feature Layer" === a.resourceInfo.type ? (a.capabilities && (a.resourceInfo.capabilities = a.capabilities), g = new u(A(a.url), {
                resourceInfo: a.resourceInfo,
                opacity: a.opacity,
                visible: a.visibility,
                id: a.id,
                mode: oa(a.url) ? u.MODE_AUTO : l.isDefined(a.mode) ? a.mode : u.MODE_ONDEMAND,
                editable: !1 === d.editable ? !1 : void 0,
                outFields: ["*"],
                autoGeneralize: !0,
                refreshInterval: a.refreshInterval
            }), !d.ignorePopups &&
            a.popupInfo && g.setInfoTemplate(new h(a.popupInfo)), a.layerDefinition && (a.layerDefinition.drawingInfo && a.layerDefinition.drawingInfo.renderer && (c = K.fromJson(a.layerDefinition.drawingInfo.renderer), c.isMaxInclusive = !0, g.setRenderer(c)), a.layerDefinition.drawingInfo && a.layerDefinition.drawingInfo.labelingInfo && (c = k.map(a.layerDefinition.drawingInfo.labelingInfo, function (a) {
                return new gb(a)
            }), g.setLabelingInfo(c)), a.layerDefinition.definitionExpression && g.setDefinitionExpression(a.layerDefinition.definitionExpression),
            l.isDefined(a.layerDefinition.minScale) && g.setMinScale(a.layerDefinition.minScale), l.isDefined(a.layerDefinition.maxScale) && g.setMaxScale(a.layerDefinition.maxScale)), fb(g)) : a.resourceInfo && a.resourceInfo.streamUrls && (c = {
                resourceInfo: a.resourceInfo,
                opacity: a.opacity,
                visible: a.visibility,
                id: a.id
            }, a.layerDefinition && (q = a.layerDefinition.drawingInfo, a.layerDefinition.definitionGeometry && (p = p || {}, p.geometry = a.layerDefinition.definitionGeometry), l.isDefined(a.layerDefinition.definitionExpression) && (p =
                p || {}, p.where = a.layerDefinition.definitionExpression), l.isDefined(a.layerDefinition.maximumTrackPoints) && (c.maximumTrackPoints = a.layerDefinition.maximumTrackPoints)), p && (c.filter = p), a.purgeOptions && (c.purgeOptions = a.purgeOptions), g = new hb(A(a.url), c), q && q.renderer && (c = q.renderer, g.setRenderer(K.fromJson(c))), !d.ignorePopups && a.popupInfo && g.setInfoTemplate(new h(a.popupInfo)), a.layerDefinition && (l.isDefined(a.layerDefinition.minScale) && g.setMinScale(a.layerDefinition.minScale), l.isDefined(a.layerDefinition.maxScale) &&
            g.setMaxScale(a.layerDefinition.maxScale)), Da.once(g, "error", function (b) {
                a.errors.push({message: "Error loading stream layer. Check websocket url"})
            }));
            g && (g.arcgisProps = {title: a.title}, a.baseMapLayer && (a.isReference ? (g.attr("data-reference", !0), g._basemapGalleryLayerType = "reference") : g._basemapGalleryLayerType = "basemap"));
            return g
        }

        function ta(a, e, d, c, b) {
            k.forEach(a, function (g) {
                g.layerObject = Va(g, a, e, d, c, b)
            });
            var f = k.filter(a, function (a) {
                return !a.isReference
            }), g = k.filter(a, function (a) {
                return !!a.isReference
            });
            return a = f.concat(g)
        }

        function ua(a) {
            var e = null;
            a = a[0];
            a.url && !a.type ? a.resourceInfo.spatialReference && (e = new B, a.resourceInfo.spatialReference.wkid && (e.wkid = a.resourceInfo.spatialReference.wkid), a.resourceInfo.spatialReference.wkt && (e.wkt = a.resourceInfo.spatialReference.wkt)) : a.type && (-1 < a.type.indexOf("BingMaps") || "OpenStreetMap" == a.type ? e = new B({wkid: 102100}) : "WMS" == a.type && (e = new B({wkid: a.spatialReferences[0]})));
            return e
        }

        function ib(a, e, d, c, b, f, g, h) {
            k.forEach(e, function (b) {
                b.url && !b.type && (b.resourceInfo =
                    a[b.deferredsPos][1], delete b.deferredsPos)
            });
            f = f || ua(e);
            e = ta(e, d, f, g, h);
            b.callback(e);
            return b
        }

        function fb(a) {
            !window.CanvasRenderingContext2D && (a.renderer && "esri.renderer.HeatmapRenderer" === a.renderer.declaredClass) && a.setRenderer(K.fromJson({
                type: "simple",
                symbol: {
                    color: [77, 77, 77, 255],
                    size: 6,
                    angle: 0,
                    xoffset: 0,
                    yoffset: 0,
                    type: "esriSMS",
                    style: "esriSMSCircle",
                    outline: {color: [255, 255, 255, 255], width: 0.75, type: "esriSLS", style: "esriSLSSolid"}
                }
            }))
        }

        function jb(a, e) {
            var d = A(a);
            return z({
                url: d, content: {f: "json"},
                callbackParamName: "callback", error: function (a, b) {
                    a.message = a.message ? a.message + (" [url:" + d + "]") : "[url:" + d + "]";
                    e.push(a);
                    J.defaults.io.errorHandler(a, b)
                }
            })
        }

        function kb(a) {
            var e = s.arcgisUrl + "/" + a.itemId + "/data";
            return z({
                url: e, content: {f: "json"}, callbackParamName: "callback", error: function (d, c) {
                    d.message = d.message ? d.message + (" [url:" + e + "]") : "[url:" + e + "]";
                    a.errors = a.errors || [];
                    a.errors.push(d);
                    J.defaults.io.errorHandler(d, c)
                }
            })
        }

        function lb(a, e, d) {
            var c = new r;
            if ((!d.featureCollection || !d.featureCollection.layers) && !d.layers)return console.log("Invalid Feature Collection item data [item id: " + a.itemId + "]: ", d), a.errors = a.errors || [], a.errors.push({message: "Invalid Feature Collection item data. [item id: " + a.itemId + "]"}), c.errback(), c;
            d.layers && (d.featureCollection = {layers: d.layers}, delete d.layers, l.isDefined(d.showLegend) && (d.featureCollection.showLegend = d.showLegend, delete d.showLegend));
            mb(a, d.featureCollection, e).then(function (b) {
                d.featureCollection = b;
                a.featureCollection && a.featureCollection.layers ? k.forEach(d.featureCollection.layers,
                    function (b, d) {
                        var c = a.featureCollection.layers[d];
                        if (!c.poupInfo && !c.layerDefinition)c.popupInfo = b.popupInfo, c.layerDefinition = b.layerDefinition; else if (c.layerDefinition) {
                            if (l.isDefined(c.layerDefinition.minScale) && l.isDefined(c.layerDefinition.maxScale) && (c.layerDefinition.minScale !== b.layerDefinition.minScale || c.layerDefinition.maxScale !== b.layerDefinition.maxScale))delete b.layerDefinition.minscale, delete b.layerDefinition.maxScale;
                            c.layerDefinition.drawingInfo && I.toJson(c.layerDefinition.drawingInfo) !==
                            I.toJson(b.layerDefinition.drawingInfo) && delete b.layerDefinition.drawingInfo;
                            c.layerDefinition.showLegend !== b.layerDefinition.showLegend && delete b.layerDefinition.showLegend;
                            c.layerDefinition = n.mixin(c.layerDefinition, b.layerDefinition)
                        } else c.layerDefinition = b.layerDefinition;
                        c.featureSet = b.featureSet;
                        c.nextObjectId = b.nextObjectId
                    }) : (a.featureCollection = a.featureCollection || {}, a.featureCollection = n.mixin(a.featureCollection, d.featureCollection));
                c.callback(a)
            });
            return c
        }

        function mb(a, e, d) {
            var c =
                new r;
            H(["./csv"], function (b) {
                var f = [];
                k.forEach(e.layers, function (a) {
                    a.featureSet && (a.featureSet.features && a.featureSet.features.length && a.featureSet.features[0].geometry && a.featureSet.features[0].geometry.spatialReference) && (a.deferredsPos = f.length, f.push(b.projectFeatureCollection(a, d, a.featureSet.features[0].geometry.spatialReference)))
                });
                (new C(f)).addCallback(function () {
                    k.forEach(e.layers, function (b) {
                        l.isDefined(b.deferredsPos) && (f[b.deferredsPos].results && f[b.deferredsPos].results.length ? b =
                            f[b.deferredsPos].results[0] : (console.log("Errors projecting feature collection. [" + a.title + " - " + b.layerDefinition.name + "]"), b.errors = b.errors || [], b.errors.push({message: "Errors projecting feature collection. [" + a.title + " - " + b.layerDefinition.name + "]"})), delete b.deferredsPos)
                    });
                    c.callback(e)
                })
            });
            return c
        }

        function O(a, e, d, c, b) {
            var f = new r, g = new r, h = [], m;
            k.forEach(a.operationalLayers, function (a) {
                a.itemId && "Feature Collection" == a.type && h.push(kb(a).then(n.hitch(null, lb, a, d)))
            });
            0 === h.length ? nb(a,
                e, d, c, g, b) : (m = new C(h), m.addCallback(function (f) {
                nb(a, e, d, c, g, b)
            }));
            g.then(function (a) {
                h = [];
                k.forEach(a, function (a) {
                    a = a.layerObject;
                    if (a instanceof u && !a.loaded && !a.loadError) {
                        var b = new r;
                        Da.once(a, "load, error", function () {
                            b.callback(a)
                        });
                        h.push(b)
                    }
                });
                if (h.length) {
                    var b = new r;
                    m = new C(h);
                    m.addCallback(function () {
                        b.callback(a)
                    });
                    return b.promise
                }
                return a
            }).then(function (a) {
                var b = [];
                k.forEach(a, function (a) {
                    if (a.layerObject instanceof u) {
                        var d = a.layerObject;
                        d.loaded && (d.labelingInfo && (a.showLabels || d._collection)) &&
                        b.push(d)
                    }
                });
                b.length ? H(["esri/layers/LabelLayer"], function (d) {
                    var c = new d;
                    k.forEach(b, function (a) {
                        c.addFeatureLayer(a)
                    });
                    a.push({layerObject: c});
                    f.callback(a)
                }) : f.callback(a)
            });
            return f
        }

        function nb(a, e, d, c, b, f) {
            var g = [], h = [], m = [];
            k.forEach(a.operationalLayers, function (a, b) {
                if (a.featureCollection && a.featureCollection.layers) {
                    var d = a.featureCollection.layers.length;
                    k.forEach(a.featureCollection.layers, function (c, e) {
                        var g = !0;
                        a.visibleLayers && -1 == k.indexOf(a.visibleLayers, e) && (g = !1);
                        c.visibility = a.visibility &&
                            g;
                        c.opacity = a.opacity;
                        c.id = (a.id || "operational" + b) + "_" + e;
                        a.title && (c.title = 1 === d || !c.layerDefinition.name || a.title === c.layerDefinition.name ? a.title : a.title + " - " + c.layerDefinition.name);
                        m.push(c)
                    }, this)
                } else m.push(a)
            });
            k.forEach(a.baseMap.baseMapLayers, function (a, b) {
                a.baseMapLayer = !0;
                a.id = a.id || "base" + b;
                g.push(a)
            });
            k.forEach(m, function (a, b) {
                a.id = a.id || "operational" + b;
                g.push(a)
            });
            k.forEach(g, function (a) {
                a.url && !a.type && (a.deferredsPos = h.length, a.errors = a.errors || [], h.push(jb(a.url, a.errors)))
            });
            0 ===
            h.length ? (d = d || ua(g), g = ta(g, e, d, c, f), b.callback(g)) : (new C(h)).addCallback(function (a) {
                ib(a, g, e, h, b, d, c, f)
            });
            return b
        }

        function P(a, e, d, c) {
            var b = a.minScale, f = a.maxScale;
            if (10.1 >= d.version && e)for (a = e.length - 1; 0 <= a; a--) {
                if (e[a].id == c)if (0 == b && 0 < e[a].minScale ? b = e[a].minScale : 0 < b && 0 == e[a].minScale ? b = d.minScale : 0 < b && 0 < e[a].minScale && (b = Math.min(b, e[a].minScale)), f = Math.max(d.maxScale || 0, e[a].maxScale || 0), d.setScaleRange(b, f), -1 < e[a].parentLayerId)c = e[a].parentLayerId; else break
            } else 10.1 < d.version && (k.forEach(a.layerInfos,
                function (a) {
                    a.id == c && (0 == b && 0 < a.minScale ? b = a.minScale : 0 < b && 0 == a.minScale || 0 < b && 0 < a.minScale && (b = Math.min(b, a.minScale)), f = Math.max(f || 0, a.maxScale || 0))
                }), d.setScaleRange(b, f))
        }

        function Q(a, e, d, c) {
            var b = a.url, f = a.__popupIds, g = a.__popupUrls, h = a.__popupWhereClauses, m = a.__popupMinScales, v = a.__popupMaxScales, p = a.__resourceInfo, q = [];
            k.forEach(a.__popups, function (c, n) {
                if (c) {
                    var x, s = [];
                    k.forEach(c.fieldInfos, function (a) {
                        "shape" !== a.fieldName.toLowerCase() && s.push(a.fieldName)
                    });
                    if (a.dynamicLayerInfos && 0 <
                        a.dynamicLayerInfos.length) {
                        var r = k.filter(a.dynamicLayerInfos, function (a) {
                            return f[n] == a.id
                        })[0].source;
                        x = new u(b + "/dynamicLayer", {
                            id: a.id + "_" + f[n],
                            source: r,
                            outFields: s,
                            mode: u.MODE_SELECTION,
                            infoTemplate: c && new d(c),
                            drawMode: !1,
                            visible: a.visible,
                            autoGeneralize: !0
                        });
                        var w = function (b, c) {
                            0 < h[b].length && c.setDefinitionExpression(h[b]);
                            if (!l.isDefined(m[b]) && !l.isDefined(v[b]))P(a, e || p.layers, c, f[b]); else if (l.isDefined(a.minScale) || l.isDefined(a.maxScale)) {
                                var d = a.minScale, g = a.maxScale;
                                0 == d && 0 < m[b] ?
                                    d = m[b] : 0 < d && 0 == m[b] || 0 < d && 0 < m[b] && (d = Math.min(d, m[b]));
                                g = Math.max(g || 0, v[b] || 0);
                                c.setScaleRange(d, g)
                            } else c.setScaleRange(m[b], v[b])
                        };
                        x.loaded ? w(n, x) : t.connect(x, "onLoad", function (a) {
                            w(n, x)
                        })
                    } else {
                        var y = null, z = b + "/" + f[n];
                        if (g[n].length)z = g[n]; else if (e)for (r = 0; r < e.length; r++)if (e[r].id === f[n]) {
                            y = e[r];
                            break
                        }
                        x = new u(A(z), {
                            id: a.id + "_" + f[n],
                            outFields: s,
                            mode: u.MODE_SELECTION,
                            infoTemplate: c && new d(c),
                            drawMode: !1,
                            visible: a.visible,
                            resourceInfo: y,
                            autoGeneralize: !0
                        });
                        x.loaded ? (0 < h[n].length && x.setDefinitionExpression(h[n]),
                            P(a, e || p.layers, x, f[n])) : t.connect(x, "onLoad", function (b) {
                            0 < h[n].length && x.setDefinitionExpression(h[n]);
                            P(a, e || p.layers, b, f[n])
                        })
                    }
                    q.push(x)
                }
            });
            0 < q.length && (t.connect(a, "onVisibilityChange", n.hitch(this, function (a, b) {
                k.forEach(a, function (a) {
                    b ? a.show() : a.hide()
                })
            }, q)), t.connect(c, "onLayerRemove", n.hitch(this, function (a, b, d) {
                a.id === d.id && k.forEach(b, function (a) {
                    c.removeLayer(a)
                })
            }, a, q)));
            delete a.__popups;
            delete a.__popupIds;
            delete a.__popupUrls;
            delete a.__popupWhereClauses;
            delete a.__popupMinScales;
            delete a.__popupMaxScales;
            delete a.__resourceInfo;
            return q
        }

        function ob(a) {
            return z({
                url: A(a.url + "/layers"),
                content: {f: "json"},
                callbackParamName: "callback",
                error: function () {
                }
            })
        }

        function pb(a, e, d) {
            var c = [];
            k.forEach(a, function (a) {
                var b = a.__popups;
                b && (1 < b.length && 10 <= a.version) && (a.__deferredsPos = c.length, c.push(ob(a)))
            });
            var b = [];
            0 < c.length ? (new C(c)).addCallback(function (c) {
                k.forEach(a, function (a) {
                    a.__popups && 0 < a.__popups.length && (a.__deferredsPos || 0 === a.__deferredsPos ? (b = b.concat(Q(a, c[a.__deferredsPos][1].layers,
                        d, e)), delete a.__deferredsPos) : b = b.concat(Q(a, null, d, e)))
                });
                e.addLayers(b)
            }) : (k.forEach(a, function (a) {
                a.__popups && 0 < a.__popups.length && (b = b.concat(Q(a, null, d, e)))
            }), e.addLayers(b))
        }

        function qb(a) {
            k.forEach(a, function (a) {
                var d = a.layer;
                d.toJson && (a = d.toJson(), a.featureSet && (d.name && -1 < d.name.indexOf("Text")) && k.forEach(a.featureSet.features, function (a, b) {
                    if (a.attributes.TEXT) {
                        var e = d.graphics[b];
                        e.symbol.setText(a.attributes.TEXT);
                        a.symbol.horizontalAlignment && (e.symbol.align = a.symbol.horizontalAlignment);
                        e.setSymbol(e.symbol);
                        e.setAttributes(a.attributes)
                    }
                }, this))
            })
        }

        function rb(a) {
            var e = 6;
            k.forEach(a, function (a) {
                if (a = a.renderer)"esri.renderer.SimpleRenderer" === a.declaredClass ? ((a = a.symbol) && a.xoffset && (e = Math.max(e, Math.abs(a.xoffset))), a && a.yoffset && (e = Math.max(e, Math.abs(a.yoffset)))) : ("esri.renderer.UniqueValueRenderer" === a.declaredClass || "esri.renderer.ClassBreaksRenderer" === a.declaredClass) && k.forEach(a.infos, function (a) {
                    (a = a.symbol) && a.xoffset && (e = Math.max(e, Math.abs(a.xoffset)));
                    a && a.yoffset &&
                    (e = Math.max(e, Math.abs(a.yoffset)))
                })
            });
            return e
        }

        function va(a) {
            var e = this, d = e.infoWindow, c = a.graphic;
            if (e.loaded) {
                d.hide();
                d.clearFeatures();
                var b = [];
                k.forEach(e.graphicsLayerIds, function (a) {
                    if ((a = e.getLayer(a)) && a instanceof u && a.loaded && a.visible)a.clearSelection(), a.infoTemplate && !a.suspended && b.push(a)
                });
                k.forEach(e.layerIds, function (a) {
                    (a = e.getLayer(a)) && (-1 !== a.declaredClass.indexOf("ArcGISImageServiceLayer") && a.loaded && a.visible && a.infoTemplate) && b.push(a)
                });
                c = c && c.getInfoTemplate() ? c : null;
                if (b.length || c) {
                    var f = rb(b), g = a.screenPoint, h = e.toMap(new Ga(g.x - f, g.y + f)), f = e.toMap(new Ga(g.x + f, g.y - f)), h = new D(h.x, h.y, f.x, f.y, e.spatialReference), m = new Ab;
                    m.geometry = h;
                    m.timeExtent = e.timeExtent;
                    var l = !0, h = k.map(b, function (b) {
                        var c;
                        -1 !== b.declaredClass.indexOf("ArcGISImageServiceLayer") ? (m.geometry = a.mapPoint, l = !1, c = b.queryVisibleRasters(m, {
                            rasterAttributeTableFieldPrefix: "Raster.",
                            returnDomainValues: !0
                        }), c.addCallback(function () {
                            return b.getVisibleRasters()
                        })) : (c = b.selectFeatures(m), c.addCallback(function () {
                            return b.getSelectedFeatures()
                        }));
                        return c
                    });
                    c && (f = new r, f.callback([c]), h.splice(0, 0, f));
                    if (!k.some(h, function (a) {
                            return -1 === a.fired
                        })) {
                        var p = c ? 1 : 0;
                        k.forEach(b, function (a) {
                            p = -1 !== a.declaredClass.indexOf("ArcGISImageServiceLayer") ? p + a.getVisibleRasters().length : p + a.getSelectedFeatures().length
                        });
                        if (!p)return
                    }
                    d.setFeatures(h);
                    d.show(a.mapPoint, {closestFirst: l})
                }
            }
        }

        function Gb(a, e) {
            var d = e.mapOptions || {}, c;
            d.infoWindow || (c = new zb({visibleWhenEmpty: !1}, wb.create("div")), d.infoWindow = c);
            !l.isDefined(d.showInfoWindowOnClick) && !e.usePopupManager &&
            (d.showInfoWindowOnClick = !1);
            d = new xb(a, d);
            t.connect(d, "onLayersAddResult", qb);
            return d
        }

        function y(a, e, d, c, b, f) {
            var g, h, m, l;
            c.map ? (g = c.map, h = c.clickEventHandle, m = c.clickEventListener, l = c.errors) : (g = Gb(c, b), !b.ignorePopups && (!b.disableClickBehavior && !b.usePopupManager) && (h = t.connect(g, "onClick", va), m = va));
            g.addLayers(a);
            !b.ignorePopups && !b.usePopupManager && pb(a, g, b._clazz);
            var p = l || [];
            k.forEach(e, function (a) {
                a.errors && (p = p.concat(a.errors))
            }, this);
            g.loaded ? f.callback({
                map: g, itemInfo: d, errors: p, clickEventHandle: h,
                clickEventListener: m
            }) : t.connect(g, "onLoad", function () {
                f.callback({map: g, itemInfo: d, errors: p, clickEventHandle: h, clickEventListener: m})
            })
        }

        function R(a, e, d, c, b) {
            var f = [];
            k.forEach(b, function (a) {
                n.isArray(a.layerObject) ? k.forEach(a.layerObject, function (a) {
                    f.push(a)
                }) : f.push(a.layerObject)
            });
            if ("BingMapsAerial" === b[0].type || "BingMapsRoad" === b[0].type || "BingMapsHybrid" === b[0].type)var g = setInterval(function () {
                if (b[0].layerObject && b[0].layerObject.loaded)clearInterval(g), sb(a, e, d, c, b, f); else if (b[0].errors) {
                    clearInterval(g);
                    var h = "";
                    b[0].errors && b[0].errors.length && (h = " (" + b[0].errors[0].message + ")");
                    c.errback(Error(ha.arcgis.utils.baseLayerError + h))
                }
            }, 10); else if (!f[0] && b[0].baseMapLayer) {
                var h = "";
                b[0].errors && b[0].errors.length && (h = " (" + b[0].errors[0].message + ")");
                c.errback(Error(ha.arcgis.utils.baseLayerError + h))
            } else sb(a, e, d, c, b, f)
        }

        function sb(a, e, d, c, b, f) {
            try {
                var g = d.mapOptions || {};
                d.mapOptions = g;
                var h = a.item;
                f = k.filter(f, l.isDefined);
                if (h)if (h.extent && h.extent.length)if (g.extent)y(f, b, a, e, d, c); else {
                    var m = new D(h.extent[0][0],
                        h.extent[0][1], h.extent[1][0], h.extent[1][1], new B({wkid: 4326})), n = f[0].spatialReference;
                    4326 === n.wkid ? (g.extent = m, y(f, b, a, e, d, c)) : 102100 === n.wkid || 102113 === n.wkid || 3857 === n.wkid ? (m.xmin = Math.max(m.xmin, -180), m.xmax = Math.min(m.xmax, 180), m.ymin = Math.max(m.ymin, -89.99), m.ymax = Math.min(m.ymax, 89.99), g.extent = yb.geographicToWebMercator(m), y(f, b, a, e, d, c)) : d.geometryServiceURL || J.defaults.geometryService ? (d.geometryServiceURL ? new Bb(d.geometryServiceURL) : J.defaults.geometryService).project([m], n, function (h) {
                        h =
                            h[0];
                        g.extent = g.extent || h;
                        y(f, b, a, e, d, c)
                    }, function () {
                        y(f, b, a, e, d, c)
                    }) : c.errback(Error(ha.arcgis.utils.geometryServiceError))
                } else y(f, b, a, e, d, c); else y(f, b, a, e, d, c)
            } catch (p) {
                c.errback(p)
            }
        }

        function Hb(a) {
            var e = [];
            k.forEach(a.operationalLayers, function (a) {
                a.featureCollection ? e.push({
                    featureCollection: a.featureCollection,
                    visibility: a.visibility,
                    title: a.title
                }) : a.layerObject && e.push({layer: a.layerObject, visibility: a.visibility, title: a.title})
            });
            return e
        }

        function tb(a) {
            var e = [];
            a = a.baseMap.baseMapLayers.concat(a.operationalLayers);
            k.forEach(a, function (a) {
                var c = {};
                if (a.featureCollection && "CSV" !== a.type)!0 === a.featureCollection.showLegend && k.forEach(a.featureCollection.layers, function (b) {
                    if (!1 !== b.showLegend) {
                        var f = b.layerObject.renderer;
                        c = {
                            layer: b.layerObject,
                            title: a.title,
                            defaultSymbol: f && f.defaultSymbol && f.defaultLabel ? !0 : !1
                        };
                        1 < a.featureCollection.layers.length && (c.title += " - " + b.layerDefinition.name);
                        e.push(c)
                    }
                }); else if (a.baseMapLayer && !0 === a.showLegend && a.layerObject || !a.baseMapLayer && !1 !== a.showLegend && a.layerObject && !(a.layerObject instanceof u && a.layerObject.mode === u.MODE_SELECTION)) {
                    var b = a.layerObject.renderer, f = a.layerObject.declaredClass, b = !b || b && b.defaultSymbol && b.defaultLabel ? !0 : !1;
                    if (10.1 > a.layerObject.version && ("esri.layers.ArcGISDynamicMapServiceLayer" === f || "esri.layers.ArcGISTiledMapServiceLayer" === f) || "esri.layers.ArcGISImageServiceLayer" === f)b = !0;
                    c = {layer: a.layerObject, title: a.title, defaultSymbol: b};
                    a.layers && (f = k.map(k.filter(a.layers, function (a) {
                        return !1 === a.showLegend
                    }), function (a) {
                        return a.id
                    }),
                    f.length && (c.hideLayers = f));
                    e.push(c)
                }
            });
            return e
        }

        function Ib(a, e) {
            function d(a, b) {
                k.forEach(a, function (a, c) {
                    switch (a) {
                        case S:
                            Na = b[c];
                            break;
                        case T:
                            Ua = b[c];
                            break;
                        case U:
                            Ta = b[c];
                            break;
                        case wa:
                            cb = b[c];
                            break;
                        case V:
                            db = b[c];
                            break;
                        case xa:
                            Oa = b[c];
                            break;
                        case W:
                            bb = b[c];
                            break;
                        case ya:
                            Ma = b[c];
                            break;
                        case X:
                            Qa = b[c];
                            break;
                        case Y:
                            Za = b[c];
                            break;
                        case Z:
                            gb = b[c];
                            break;
                        case za:
                            Pa = b[c];
                            break;
                        case $:
                            Sa = b[c];
                            break;
                        case aa:
                            Wa = b[c];
                            break;
                        case ba:
                            Ra = b[c];
                            break;
                        case ca:
                            hb = b[c];
                            break;
                        case Aa:
                            ab = b[c];
                            break;
                        case Ba:
                            la = b[c];
                            break;
                        case da:
                            eb = b[c];
                            break;
                        case ea:
                            w = b[c];
                            break;
                        case fa:
                            $a = b[c];
                            break;
                        case ga:
                            Ya = b[c];
                            break;
                        case Ca:
                            Xa = b[c]
                    }
                })
            }

            var c = new r, b = a.itemData, f = [];
            b.baseMap && b.baseMap.baseMapLayers && (f = f.concat(b.baseMap.baseMapLayers));
            b.operationalLayers && (f = f.concat(b.operationalLayers));
            for (var b = k.map(f, function (a) {
                return a && a.layerType
            }), g = [], h = [], f = !1, m = 0; m < b.length; m++) {
                switch (b[m]) {
                    case "ArcGISFeatureLayer":
                        -1 === k.indexOf(g, Z) && g.push(Z);
                        break;
                    case "ArcGISImageServiceLayer":
                    case "ArcGISTiledImageServiceLayer":
                        -1 ===
                        k.indexOf(g, T) && (g.push(T), h.push(X), h.push($), h.push(ba));
                        break;
                    case "ArcGISImageServiceVectorLayer":
                        -1 === k.indexOf(g, U) && (g.push(U), h.push(X), h.push($), h.push(ba));
                        break;
                    case "ArcGISMapServiceLayer":
                    case "ArcGISTiledMapServiceLayer":
                        -1 === k.indexOf(g, S) && (g.push(S), h.push(xa), h.push(ya), h.push(za));
                        break;
                    case "ArcGISStreamLayer":
                        -1 === k.indexOf(g, ca) && g.push(ca);
                        break;
                    case "BingMapsAerial":
                    case "BingMapsHybrid":
                    case "BingMapsRoad":
                        -1 === k.indexOf(g, ea) && g.push(ea);
                        break;
                    case "CSV":
                        -1 === k.indexOf(g,
                            V) && (g.push(V), h.push(wa));
                        break;
                    case "GeoRSS":
                        -1 === k.indexOf(g, W) && g.push(W);
                        break;
                    case "KML":
                        -1 === k.indexOf(g, Y) && g.push(Y);
                        break;
                    case "OpenStreetMap":
                        -1 === k.indexOf(g, aa) && g.push(aa);
                        break;
                    case "VectorTileLayer":
                        -1 === k.indexOf(g, da) && (g.push(da), Ea("ie") || h.push(Ba));
                        break;
                    case "WebTiledLayer":
                        -1 === k.indexOf(g, fa) && (g.push(fa), h.push(Aa));
                        break;
                    case "WMS":
                        -1 === k.indexOf(g, ga) && (g.push(ga), h.push(Ca));
                        break;
                    default:
                        f = !0
                }
                if (f)break
            }
            f && (g = Jb, h = Kb);
            g.length ? H(g, function () {
                d(g, arguments);
                h.length ? H(h,
                    function () {
                        d(h, arguments);
                        c.resolve()
                    }) : c.resolve()
            }) : c.resolve();
            return c
        }

        function ub(a, e, d, c) {
            var b = c.itemData;
            b.baseMap && (b.baseMap.baseMapLayers && b.baseMap.baseMapLayers.length) && (b.baseMap.baseMapLayers[0].firstLayer = !0);
            var f = e.layerMixins, g = f && f.length;
            if (g) {
                var h = function (a) {
                    for (var b = 0; b < g; b++) {
                        var c = f[b];
                        if (c.mixin)if (c.hasOwnProperty("id")) {
                            if (a.id === c.id) {
                                n.mixin(a, c.mixin);
                                break
                            }
                        } else if (a.url === c.url) {
                            n.mixin(a, c.mixin);
                            break
                        }
                    }
                };
                k.forEach(b.baseMap && b.baseMap.baseMapLayers, h);
                k.forEach(b.operationalLayers,
                    h)
            }
            Ib(c, e).then(function () {
                return Eb(c, e)
            }).then(function () {
                return Db(c, e)
            }).then(function (b) {
                var c = b[0], e = b[1];
                if (!c.itemData.operationalLayers || 0 === c.itemData.operationalLayers.length)L(c, e).addCallback(function (b) {
                    O(b.itemData, e).addCallback(n.hitch(null, R, b, a, e, d))
                }); else {
                    var f = new r, g = c.itemData.baseMap.baseMapLayers.slice(), h = k.filter(c.itemData.baseMap.baseMapLayers, function (a) {
                        return !a.isReference
                    });
                    b = {item: c.item, itemData: {baseMap: {baseMapLayers: h}}};
                    c.itemData.baseMap.baseMapLayers = k.filter(c.itemData.baseMap.baseMapLayers,
                        function (a) {
                            return a.isReference
                        });
                    L(b, e).addCallback(function (b) {
                        O(b.itemData, e).addCallback(n.hitch(null, R, b, a, e, f))
                    });
                    f.then(function (a) {
                        L(c, e).addCallback(function (b) {
                            O(b.itemData, e, a.map.spatialReference, h, a.map).addCallback(function (c) {
                                b.itemData.baseMap.baseMapLayers = g;
                                R(b, a, e, d, c)
                            })
                        })
                    }, n.hitch(d, d.errback))
                }
            })
        }

        function ma(a, e) {
            "undefined" === typeof e && (e = !0);
            s._arcgisUrl && 0 < s._arcgisUrl.length && (s.arcgisUrl = s._arcgisUrl);
            var d = s.arcgisUrl + "/" + a, c = {}, b = new r;
            z({
                url: d, content: {f: "json"}, callbackParamName: "callback",
                load: function (a) {
                    c.item = a;
                    e ? z({
                        url: d + "/data", content: {f: "json"}, callbackParamName: "callback", load: function (a) {
                            c.itemData = a;
                            b.callback(c)
                        }, error: function (a) {
                            b.errback(a)
                        }
                    }) : b.callback(c)
                }, error: function (a) {
                    b.errback(a)
                }
            });
            return b
        }

        function myMa(a, e) {
            "undefined" === typeof e && (e = !0);
            s._arcgisUrl && 0 < s._arcgisUrl.length && (s.arcgisUrl = s._arcgisUrl);
            var d = "configs/layer/items.json", c = {}, b = new r;
            z({
                url: d, content: {f: "json"}, callbackParamName: "callback",
                load: function (a) {
                    c.item = a;
                    e ? z({
                        url: "configs/layer/layers.json", content: {f: "json"}, callbackParamName: "callback", load: function (a) {
                            c.itemData = a;
                            b.callback(c)
                        }, error: function (a) {
                            b.errback(a)
                        }
                    }) : b.callback(c)
                }, error: function (a) {
                    b.errback(a)
                }
            });
            return b
        }

        var s, Na, Ua, Ta, cb, db, Oa, bb, Ma, Qa, Za, gb, Pa, Sa, Wa, Ra, hb, ab, la, eb, w, $a, Ya, Xa, S = "esri/layers/ArcGISDynamicMapServiceLayer", T = "esri/layers/ArcGISImageServiceLayer", U = "esri/layers/ArcGISImageServiceVectorLayer", wa = "./csv", V = "esri/layers/CSVLayer", xa = "esri/layers/DynamicLayerInfo", W = "esri/layers/GeoRSSLayer",
            ya = "esri/layers/ImageParameters", X = "esri/layers/ImageServiceParameters", Y = "esri/layers/KMLLayer", Z = "esri/layers/LabelClass", za = "esri/layers/LayerDrawingOptions", $ = "esri/layers/MosaicRule", aa = "esri/layers/OpenStreetMapLayer", ba = "esri/layers/RasterFunction", ca = "esri/layers/StreamLayer", Aa = "esri/layers/TileInfo", Ba = "esri/layers/vector-tile", da = "esri/layers/VectorTileLayer", ea = "esri/virtualearth/VETiledLayer", fa = "esri/layers/WebTiledLayer", ga = "esri/layers/WMSLayer", Ca = "esri/layers/WMSLayerInfo", Jb = [S, T, U, V, W, Y, Z, aa, ca, da, ea, fa, ga],
            Kb = [wa, xa, ya, X, za, $, ba, Aa, Ba, Ca];
        s = {
            arcgisUrl: location.protocol + "//www.arcgis.com/sharing/rest/content/items",
            getItem: ma,
            createMap: function (a, e, d) {
                var c = new r;
                d = d || {};
                var b = d.infoTemplateClass;
                d._clazz = b && (n.isObject(b) ? b : n.getObject(b)) || Ha;
                n.isString(a) ? myMa(a).addCallback(n.hitch(null, ub, e, d, c)).addErrback(n.hitch(c, c.errback)) : ub(e, d, c, a);
                return c
            },
            getLayerList: function (a) {
                return a && a.itemInfo && a.itemInfo.itemData ? Hb(a.itemInfo.itemData) : []
            },
            getLegendLayers: function (a) {
                return a && a.itemInfo && a.itemInfo.itemData ?
                    tb(a.itemInfo.itemData) : []
            },
            _arcgisUrl: null,
            _getItemProps: L,
            _getItemData: F,
            _getBingKey: ia,
            _portalUrlResponse: ka,
            _portalUrlFailure: M,
            _processFSItemProperties: ja,
            _processSSItemProperties: Ia,
            _getLayers: O,
            _preBuildLayerObjects: ib,
            _buildLayerObjects: ta,
            _preCreateMap: R,
            _getMapSR: ua,
            _createMap: y,
            _addSelectionLayers: pb,
            _createSelectionFeatureLayers: Q,
            _getServiceInfo: jb,
            _getFeatureCollectionItem: kb,
            _mergeFeatureCollectionItem: lb,
            _projectFeatureCollection: mb,
            _getLayersInfo: ob,
            _initLayer: Va,
            _loadAsCached: pa,
            _loadAsDynamic: La,
            _processPopups: na,
            _onLayersAddResult: qb,
            _sameSpatialReferenceAsBasemap: ra,
            _sameTilingSchemeAsBasemap: sa,
            _showPopup: va,
            _calculateClickTolerance: rb,
            _getVisibleFeatureLayers: qa,
            _updateLayerScaleInfo: P,
            _checkUrl: A,
            _isHostedService: oa,
            _isAgolService: Ka,
            _getLegendLayers: tb
        };
        n.setObject("arcgis.utils", s, G);
        return s
    });